var optionBar = {
	title :{
		text : '',
		textStyle : {
			fontSize : 14
		}
	},
	tooltip : {
        trigger: 'axis',
        formatter: "{b}:{c}",
        axisPointer : {
            type : 'shadow'
        }
    },
    grid: {
        left: '0',
        right: '0',
        bottom: '0',
        containLabel: true
    },
    animation : true,
    xAxis : [
        {
            type : 'category',
            data : [],
            axisTick: {
                alignWithLabel: true,
                lineStyle : {width : 0}
            },
            axisLabel: {
            		show : true,
            		interval : 0,
            		rotate :0,
            		margin:5,
            		textStyle : {
            			fontSize :11
            		}
            }
        }
    ],
    yAxis : [
        {
            type : 'value',
            position : 'left',
            axisTick: {
                alignWithLabel: true,
                inside : true
            },
            axisLabel: {
            		margin:3
            }
        }
    ],
    series : [
        {
        		name:'',
            type:'bar',
            barWidth: '60%',
            data:[]
        }
    ]
};

var optionPie = {
	title : {
		text : '',
		textStyle : {
			fontSize : 14
		}
	},
   tooltip: {
		formatter: "{b} : {c} ({d}%)"
   },
    animation : true,
    legend: {
        orient: 'vertical',
        left: 'left'
    },
    textStyle: {
       fontSize : 11
    },
    series : [
        {
            type: 'pie',
            radius : '65%',
            center: ['50%', '60%'],
            data:[],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};

/**
 * 创建报表 
 * @param {Object} url 报表后台地址
 */
function createReport(url){
	var chartDiv = byId('report');
	var barChart = createEle("div");
	
	var height = document.documentElement.clientHeight || document.body.clientHeight;
	if(mui.os.android){
		optionBar.animation = false;
		optionPie.animation = false;
		// android采用自动计算每一页的报表高度
		var relHeight = parseInt((height - 145) / 2.1);
		barChart.setAttribute("style","height: "+relHeight+"px;");
	} else {
		barChart.setAttribute("class","chart_" + height);
	}
	chartDiv.appendChild(barChart);
	barChart = echarts.init(barChart);
	app.ajax(url,null,function(data){
		if(data.type == "bar"){
			optionBar.title.text = data.name;
			barChart.setOption(optionBar);
			barChart.setOption({
	        		xAxis: {
	           		data: data.names
	        		},
	        		series: [{
	           		data: data.values
	        		}]
	    		});
		} else if(data.type == "pie"){
			optionPie.title.text = data.name;
			barChart.setOption(optionPie);
			barChart.setOption({
		    		series: [{
			       	data: data.dataList
		    		}]
			});
		}
	});
}